package com.webapp.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.webapp.domain.entity.Dict;
import com.webapp.domain.entity.MediationArea;

@Repository("mediationAreaDAO")
public class MediationAreaDAO extends AbstractDAO<MediationArea> {
	public List<MediationArea> findListByType(int type){
		String hql = "from MediationArea d where d.areaType = :areaType";
		Query query = getSession().createQuery(hql).setInteger("areaType", type);
		return query.list();
		
	}
	public MediationArea getMediationByName(String name){
		String hql = "from MediationArea d where d.areaName = :name";
		Query query = getSession().createQuery(hql).setString("name", name);
		return (MediationArea)query.list().get(0);		
	}
	public MediationArea getMediationByFullName(String name){
		String hql = "from MediationArea d where d.fullName = :name";
		Query query = getSession().createQuery(hql).setString("name", name);
		return (MediationArea)query.list().get(0);		
	}
	public MediationArea getMediationByCode(long code){
		String hql = "from MediationArea d where d.code = :code";
		Query query = getSession().createQuery(hql).setLong("code", code);
		return (MediationArea)query.list().get(0);		
	}

	public List<MediationArea> findMediationByParent(long parent){
		String hql = "from MediationArea d where d.parentCode = :parent";
		Query query = getSession().createQuery(hql).setLong("parent", parent);
		return query.list();		
	}
}
